<template>
  <basic-container>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-setting"></i> 平台采购供应
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <i class="el-icon-date"></i> 供应商订单详情
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <avue-detail ref="form" v-model="form" :option="formOption"></avue-detail>
    <!-- <avue-detail ref="form" v-model="form" :option="formOption2">
    </avue-detail>-->
    <avue-crud ref="crud" :option="detailOption" :data="detailList"></avue-crud>
    <div class="goBackBtn">
      <el-button type="primary" @click="goBack">返 回</el-button>
    </div>
  </basic-container>
</template>

<script>
import { formOption } from "../../const/crud/supply/supply_order_detail";
import { formOption as detailOption } from "../../const/crud/supply/supply_order_detail_crud";
import { detailsList } from "../../api/supply/order_list";
export default {
  data() {
    return {
      isRouterAlive: false,
      form: {},
      formOption: formOption,
      detailOption: detailOption,
      detailList: []
    };
  },
  // created() {
  //   let params = {
  //     buyOrderSn: this.$route.query.buyOrderSn
  //   };
  //   // console.log(123);
  //   // this.fetchDetail(this.reload());
  // },
   beforeRouteEnter(to, from, next) {
    next(vm => vm.fetchDetail(vm.$route.query.res.supplySn));
  },
  methods: {
    fetchDetail(supplySn) {
      detailsList({supplySn: supplySn})
        .then(response => {
          this.form = response.data.data;
          this.detailList = this.form.detailList;
        })
        .catch(() => {
          this.goBack();
        });
    },
    goBack(time = 1000) {
      let that = this;
      setTimeout(function() {
        that.$store.commit("DEL_ONE_TAG", that.$route);
        that.$router.go(-1);
      }, time);
    },
    // refreshChange() {
    //   this.fetchDetail(params);
    // }
  }
};
</script>

<style lang="scss" scoped>
.crumbs {
  margin: 20px 10px;
}
.avue-crud__img img {
  height: 100px;
  margin-left: 5px;
  -o-object-fit: contain;
  object-fit: contain;
  z-index: 999999;
}
.goBackBtn {
  margin: 40px 0 40px 0;
  border-radius: 10px;
}
</style>


